<?php
namespace Nawa\Survey\Question\Renderer;
/**
 * Radio - Survey Question Renderer  
 * This Radio render will display all anwser as
 * a radio button group
 * 
 * @author Xavier VILAIN
 * @package Nawa\Survey\Question\Renderer
 * @license #license-nawa-survey#
 * 
 */
class Radio implements \Nawa\Survey\Question\Renderer {
	
	/**
	 * Return the question rendered as a string
	 * 
	 * @return string
	 */
	public function render($question,$default = null,$readonly = false) {
		$radio = new \Fox\Html\DropList\Radio(array('comments','qa_'.$question->questionid),false,false,$default);
		$radio->label(null,true);
		if($readonly) {
			$radio->displayMode(\Fox\Html\DropList\Radio::DISPLAY_READONLY);
		}
		
		$answers = $question->answers();
		if(count($answers) > 0) {
			// We use what has been stored in the 
			// DB as radio values
		} else {
			$language = \Xview::instance()->language();
			// Check if there are default values ?
			$answers = $question->type()->param(\Nawa\Survey\Question\Type::DEFAULT_ANSWERS);
			if(!empty($answers)) {
				foreach($answers as $key => $answer) {
					if($answer['language'] == $language) {
						
					} else {
						unset($answers[$key]);
					}
				}
				$radio->options($answers,'value','label');
				return '<input type="hidden" name="qv_'.$question->questionid.'" value="'.$question->versi.'">'.$radio->display();
			}
		}
	}
}